// Desc: 
// I.C.E. module
//-----------------------------------------------------------------------------
private["_group", "_result"];
_group = _this select 0;

_result = ""; // [];

//-----------------------------------------------------------------------------
fn_GetParamIndexByName =
{
  private ["_paramName", "_dualParamArray", "_index1", "_i"];

  _paramName = _this select 0; // this is case sensitive
  _dualParamArray = _this select 1;
  
  _index1 = -1;
  if (typeName _dualParamArray != "ARRAY") exitWith
  {
    _index1;
  };
  
  _i = 0;
  {
    private ["_item1"];
    _item1 = _x;
    if (typeName _item1 != "ARRAY") then
    {
      //hint format["Warning: fn_GetParamIndexByName[""%1"", ...]: param 1 array must contain named arrays not %2\n%3", _paramName, typeName _x, _x]; // debug
    }
    else
    {    
      if (count _item1 > 0) then
      {
        private ["_equal"];
        
        _equal = (typeName (_item1 select 0) == "ARRAY" || typeName _paramName == "ARRAY");
        if (!_equal) then
        {
          _equal = ((_item1 select 0) == _paramName);
        };
        if (_equal) exitWith
        {
          _index1 = _i;
        };
      };
    };
    _i = _i + 1;
  } forEach _dualParamArray;

  _index1;
};
//-----------------------------------------------------------------------------


// count how many vehicles are in each vehicle class (eg: 5x armored, 2x cars, 4x men)
if (!(isNull _group)) then
{
  private["_index", "_count", "_vehicleClass", "_vehicles", "_vehicle", "_vehicleClassesList", "_classPath", "_class"];
  _vehicleClasses = [];
  _vehicles = [];
  {
    _vehicle = vehicle _x;
    //_isVehicle = [_vehicle] call TSD9_IsVehicle;
    //--------------------
    if (!(_vehicle in _vehicles)) then
    {
      _vehicles = _vehicles+[_vehicle];
      
      _currentVehicleClass = "";
      _classPath = configFile >> "cfgVehicles" >> typeOf _vehicle;
      if (isClass _classPath) then
      {
        _class = _classPath >> "vehicleClass";
        if (isText _class) then { _currentVehicleClass = getText _class };
      };

      _index = [_currentVehicleClass, _vehicleClasses] call fn_GetParamIndexByName;
      //['_TSD9_GetGroupVehicleClassComposition', [["_index", _index], _currentVehicleClass, _vehicleClasses]] call fn_DebugAppend; // debug
      if (_index >= 0) then
      {
        _vehicleClass = _vehicleClasses select _index;
        _count = _vehicleClass select 1;
        _vehicleClass set [1, _count+1];
        _vehicleClasses set [_index, _vehicleClass];
      }
      else
      {
        //['b', _currentVehicleClass] call fn_DebugAppend; // debug
        _vehicleClasses = _vehicleClasses + [[_currentVehicleClass, 1]];
      };
    };
  } forEach units _group;
  
  //["", _vehicleClasses] call fn_DebugAppend; // debug

  //if (count _vehicleClasses > 0) then { ["CreateMenu_Groups.sqf: _vehicleClasses "+format["%1", _group], _vehicleClasses] call fn_DebugAppend }; // debug
  _vehicleClassesList = "";
  {
    if (_vehicleClassesList != "") then { _vehicleClassesList = _vehicleClassesList + "," };
    _vehicleClassesList = _vehicleClassesList + format["%1:%2", _x select 0, _x select 1];
  } forEach _vehicleClasses;
  
  //_result = [[_vehicleClassesList, "", ""]];
  _result = _vehicleClassesList;
};

/*
if (count _result == 0) then
{
  _result = [["", "", ""]];
};
*/

_result;
